package de.tudresden.st.cbse.calendar.appointment;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class Appointment implements Serializable {
    private static final long serialVersionUID = -7096466331045706037L;
    
    @Id
	@GeneratedValue
	@Column(name="APPOINTMENT_ID")
	private long id;
	private Date start;
	private Date end;
	private String title;
	private String note;
	private boolean isPrivate;
	
	@Enumerated(EnumType.STRING)
	private AppointmentType type;

	@Deprecated
	public Appointment() {
	    super();
	}
	
    public Appointment(String title, String note, Date start, Date end, boolean isPrivate, AppointmentType type) {
        super();
        this.start = start;
        this.end = end;
        this.title = title;
        this.note = note;
        this.isPrivate = isPrivate;
        this.type = type;
    }
    public long getId() {
		return id;
	}
	public Date getStart() {
		return start;
	}
	public Date getEnd() {
		return end;
	}
	public String getTitle() {
		return title;
	}
	public String getNote() {
		return note;
	}
	public boolean isPrivate() {
		return isPrivate;
	}
	public AppointmentType getType() {
		return type;
	}

    @Override
    public int hashCode() {
        return 42*new Long(id).intValue();
    }
    
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Appointment))
            return false;
        
        return ((Appointment)obj).id == this.id;
    }

    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.GERMANY);
        return title+" ("+sdf.format(start)+" - "+sdf.format(end)+")";
    }
}
